﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InductBase;
using SharpBolt.Graphics;
using SharpBolt.Time;
using SharpBolt.Graphics.GraphicInstances;

namespace SharpBolt.Graphics.Particles
{
    public class ParticleSystem
    {
        
        public TimeManager TimeManager;
        List<ParticleEmitter> Emitters;
        public Dictionary<string,ParticleScheme> Schemes { get; private set; }
        public ParticleContainer ParticleContainer;


        public void AddEmitter(ParticleEmitter emitter){
            if (!Emitters.Contains(emitter))
                    Emitters.Add(emitter);

            emitter.ParticleSystem = this;
        }

        public void RemoveEmitter(ParticleEmitter emitter){
            if(Emitters.Contains(emitter))
                Emitters.Remove(emitter);
        }


        public ParticleSystem()
        {
            Emitters = new List<ParticleEmitter>();
            Schemes = new Dictionary<string, ParticleScheme>();
            ParticleContainer = new ParticleContainer();
        }

        public void Update()
        {
            foreach (var emitter in Emitters)
            {
                if (!emitter.Enabled) continue;
                if (emitter.Frozen) continue;

                emitter.Update(TimeManager.Delta);
            }

            ParticleContainer.UpdateParticles(TimeManager.Delta);
        }

        public void CustomDraw(Painter painter)
        {
            ParticleContainer.Draw(painter);
        }
    }
}
